home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / gmice.com / GMICE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-16  |  3.6 KB  |  151 lines

  1. /* $Header:   C:/SRC/MOUSE/PVCS/GMICE.C_V   1.0   12 Jun 1989 21:27:52  $
  2.     Dwight N. Tovey  (Adapted from the July/August 1988 issue of TURBO TECHNIX)
  3.  
  4.     Illustrates the default graphics mouse cursor, plus the four
  5.     from GMOUSCUR.H
  6. -----------------------------------------------------------------------------
  7.  
  8. $Log:   C:/SRC/MOUSE/PVCS/GMICE.C_V  $
  9. /* 
  10. /*    Rev 1.0   12 Jun 1989 21:27:52
  11. /* Initial revision.
  12. */
  13.  
  14. /* INCLUDES and DEFINES */
  15. #include    <stdio.h>
  16. #include    <dos.h>
  17. #include <graph.h>
  18. #include    <stdlib.h>
  19.  
  20. #include    "mouse.h"
  21. #include    "gmouscur.h"
  22.  
  23. #ifndef    TRUE
  24. #define    TRUE    -1
  25. #define    FALSE    0
  26. #endif
  27.  
  28. #define    EVENTMASK    0x54        /* Event when any mouse button released */
  29. #define  MAX_X       80       /* Max number of columns (text output). */
  30. #define  MAX_Y       25       /* Max number of rows (text output). */
  31.  
  32. /* LOCAL PROTOTYPES */
  33. void demo ( GCURSREC, char* );
  34. void graphic_screen ( char* );
  35. void identify ( char* );
  36. void cleanup ( void );
  37. void initGCurs ( void );
  38. void far handler( );
  39.  
  40. /* GLOBALS */
  41. union REGS reg;
  42. char path [] = "C:\SRC\MOUSE";
  43. struct videoconfig CONFIG;
  44. LocRec *M_LEFT, *M_RIGHT;
  45.  
  46. /* Global mouse event record */
  47. EVENTREC theEvents;
  48.  
  49. /******  M A I N  ******/
  50. void main ()
  51. {
  52.     resetRec *theMouse;
  53.     void far *h_ptr;              /* Pointer to handler function. */
  54.  
  55.     /* Set up for run */
  56.     initGCurs();                        /* Initialize the cursor images. */
  57.     onexit( cleanup );
  58.     theMouse = m_reset();                /* Reset the mouse. */
  59.     if ( theMouse->exists )
  60.         {                             /* Install handler. */
  61.         h_ptr = handler;
  62.         m_inst_task( EVENTMASK, FP_SEG( h_ptr ), FP_OFF( h_ptr ) );
  63.  
  64. /* Show default cursor. */
  65.         graphic_screen( "Default cursor" );
  66.         m_show();                  /* Turn on cursor. */
  67.         theEvents.flag = 0;
  68.         while( theEvents.flag == 0 );      /* Wait for click. */
  69.  
  70. /* Show the custom cursors */
  71.         demo( check, "Check" );
  72.         demo( arrow, "Left arrow" );
  73.         demo( cross, "Cross" );
  74.         demo( hand, "Pointing Hand" );
  75.         demo( iBeam, "I-Beam" );
  76.         theMouse = m_reset();
  77.         }
  78. }
  79.  
  80.  
  81. /******  C L E A N U P  ******/
  82. void cleanup()
  83. {
  84.         _setvideomode( _DEFAULTMODE );
  85. }
  86.  
  87.  
  88. /******  D E M O  ******/
  89. void demo ( GCURSREC cursor, char title[] )    /* Show graphics cursor */
  90. {
  91.     struct SREGS sr;
  92.  
  93.     identify( title );
  94.     segread( &sr );
  95.     m_graph_cursor( cursor.hotX, cursor.hotY, sr.ds,
  96.                         (unsigned) (cursor.image) );
  97.  
  98.     theEvents.flag = 0;
  99.     while( theEvents.flag == 0 );      /* Wait for click. */
  100.  
  101. }
  102.  
  103. /******  G R A P H I C __ S C R E E N  ******/
  104. void graphic_screen( char title[] )                /* Set up graphics screen. */
  105. {
  106.     int x, y;
  107.     char prompt[30];
  108.  
  109.     if ( _setvideomode( _HRESBW ) != 0 )
  110.         {
  111.         _getvideoconfig( &CONFIG );
  112.         identify( title );
  113.         strcpy( prompt, "Click left button to continue");
  114.         x = (MAX_X - strlen(prompt)) / 2;
  115.         y = MAX_Y - 20;
  116.         _settextposition( y, x );
  117.         _outtext( prompt );
  118.  
  119. /* Draw rectangle as backdrop for cursor */
  120.         _setcolor( 1 );
  121.         x = CONFIG.numxpixels / 2 - 50;
  122.         y = CONFIG.numypixels / 2 - 50;
  123.         _rectangle( _GFILLINTERIOR, x, y, x + 100, y + 100 );
  124.         }
  125. }
  126.  
  127.  
  128. /******  I D E N T I F Y  ******/
  129. void identify( char *title )
  130. {
  131.     int x;
  132.  
  133.     _setviewport( 0, 0, CONFIG.numxpixels, 30 );
  134.     _clearscreen(_GVIEWPORT);
  135.     x = (MAX_X - strlen( title)) / 2;
  136.     _settextposition( 0, x );
  137.     _outtext( title );
  138.     _setviewport( 0, 0, CONFIG.numxpixels, CONFIG.numypixels );
  139. }
  140.  
  141.  
  142. /******  I N I T G C U R S  ******/
  143. void initGCurs ( void )          /* Initialize ptrs in cursor descriptors. */
  144. {
  145.     check.image = checkIm;
  146.     arrow.image = LArrIm;
  147.     cross.image = crossIm;
  148.     hand.image  = handIm;
  149.     iBeam.image = iBeamIm;
  150. }
  151.